package com.example.myapplication.tools;


import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.example.myapplication.AppInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class GetAppInfoTools {

    public static List<AppInfo> getAppInfoList(Context context){
        PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
        List<AppInfo> appInfoList = new ArrayList<>();

        for (PackageInfo installedPackage : installedPackages) {
            appInfoList.add(new AppInfo(installedPackage));
        }

        return appInfoList;
    }

    public static List<AppInfo> getAppInfoList2(Context context){
        PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);

        return installedPackages
                .stream()
                .map(v->{return  new AppInfo(v);})
                .collect(Collectors.toList());

    }
}
